﻿namespace PMS.Client.FrmOrganType
{
    using PMS.BLL;
    using PMS.Client.Controls;
    using PMS.Client.Properties;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FrmList : Form
    {
        private OrganTypeBLL bll = new OrganTypeBLL();
        private ToolStripButton btnAdd;
        private ToolStripButton btnDelete;
        private ToolStripButton btnUpdate;
        private IContainer components = null;
        private UCDataGridView dataGridView1;
        private ToolStrip toolStrip1;
        private DataGridViewTextBoxColumn TypeID;
        private DataGridViewTextBoxColumn TypeName;

        public FrmList()
        {
            this.InitializeComponent();
            this.dataGridView1.DataSource = this.bll.GetList();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmAdd add = new FrmAdd();
            add.ShowDialog();
            if (add.DialogResult == DialogResult.OK)
            {
                this.dataGridView1.DataSource = this.bll.GetList();
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count <= 0)
            {
                MessageBox.Show("请选择要修改的行！");
            }
            else if (MessageBox.Show("确认删除？", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                int typeID = int.Parse(this.dataGridView1.SelectedRows[0].Cells["typeID"].Value.ToString());
                if (this.bll.Delete(typeID))
                {
                    this.dataGridView1.DataSource = this.bll.GetList();
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count <= 0)
            {
                MessageBox.Show("请选择要修改的行！");
            }
            else
            {
                FrmUpdate update = new FrmUpdate(int.Parse(this.dataGridView1.SelectedRows[0].Cells["typeID"].Value.ToString()));
                update.ShowDialog();
                if (update.DialogResult == DialogResult.OK)
                {
                    this.dataGridView1.DataSource = this.bll.GetList();
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(FrmList));
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            DataGridViewCellStyle style2 = new DataGridViewCellStyle();
            DataGridViewCellStyle style3 = new DataGridViewCellStyle();
            this.toolStrip1 = new ToolStrip();
            this.btnAdd = new ToolStripButton();
            this.btnUpdate = new ToolStripButton();
            this.btnDelete = new ToolStripButton();
            this.dataGridView1 = new UCDataGridView(this.components);
            this.TypeID = new DataGridViewTextBoxColumn();
            this.TypeName = new DataGridViewTextBoxColumn();
            this.toolStrip1.SuspendLayout();
            ((ISupportInitialize) this.dataGridView1).BeginInit();
            base.SuspendLayout();
            this.toolStrip1.Items.AddRange(new ToolStripItem[] { this.btnAdd, this.btnUpdate, this.btnDelete });
            this.toolStrip1.Location = new Point(0, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.RenderMode = ToolStripRenderMode.System;
            this.toolStrip1.Size = new Size(0x1d7, 0x36);
            this.toolStrip1.TabIndex = 2;
            this.toolStrip1.Text = "toolStrip1";
            this.btnAdd.Image = Resources.Icons_add;
            this.btnAdd.ImageScaling = ToolStripItemImageScaling.None;
            this.btnAdd.ImageTransparentColor = Color.Magenta;
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new Size(0x24, 0x33);
            this.btnAdd.Text = "增加";
            this.btnAdd.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnAdd.Click += new EventHandler(this.btnAdd_Click);
            this.btnUpdate.Image = Resources.Icons_update;
            this.btnUpdate.ImageScaling = ToolStripItemImageScaling.None;
            this.btnUpdate.ImageTransparentColor = Color.Magenta;
            this.btnUpdate.Name = "btnUpdate";
            this.btnUpdate.Size = new Size(0x24, 0x33);
            this.btnUpdate.Text = "修改";
            this.btnUpdate.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnUpdate.Click += new EventHandler(this.btnUpdate_Click);
            this.btnDelete.Image = (Image) manager.GetObject("btnDelete.Image");
            this.btnDelete.ImageScaling = ToolStripItemImageScaling.None;
            this.btnDelete.ImageTransparentColor = Color.Magenta;
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new Size(0x24, 0x33);
            this.btnDelete.Text = "删除";
            this.btnDelete.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnDelete.Click += new EventHandler(this.btnDelete_Click);
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.AllowUserToResizeColumns = false;
            this.dataGridView1.AllowUserToResizeRows = false;
            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            this.dataGridView1.BackgroundColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.dataGridView1.BorderStyle = BorderStyle.None;
            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            this.dataGridView1.Columns.AddRange(new DataGridViewColumn[] { this.TypeID, this.TypeName });
            style.Alignment = DataGridViewContentAlignment.MiddleLeft;
            style.BackColor = SystemColors.Window;
            style.Font = new Font("宋体", 9f, FontStyle.Regular, GraphicsUnit.Point, 0x86);
            style.ForeColor = SystemColors.ControlText;
            style.SelectionBackColor = SystemColors.Highlight;
            style.SelectionForeColor = SystemColors.ControlText;
            style.WrapMode = DataGridViewTriState.False;
            this.dataGridView1.DefaultCellStyle = style;
            this.dataGridView1.Dock = DockStyle.Fill;
            this.dataGridView1.EnableHeadersVisualStyles = false;
            this.dataGridView1.GridColor = Color.FromArgb(0xd0, 0xd7, 0xe5);
            this.dataGridView1.HighlightSelectedColumnHeaders = false;
            this.dataGridView1.Location = new Point(0, 0x36);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowTemplate.Height = 0x17;
            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            this.dataGridView1.Size = new Size(0x1d7, 0xe8);
            this.dataGridView1.TabIndex = 4;
            this.TypeID.DataPropertyName = "TypeID";
            style2.Alignment = DataGridViewContentAlignment.MiddleCenter;
            style2.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.TypeID.DefaultCellStyle = style2;
            this.TypeID.FillWeight = 10f;
            this.TypeID.HeaderText = "ID";
            this.TypeID.Name = "TypeID";
            this.TypeID.ReadOnly = true;
            this.TypeID.Visible = false;
            this.TypeName.DataPropertyName = "TypeName";
            style3.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.TypeName.DefaultCellStyle = style3;
            this.TypeName.FillWeight = 90f;
            this.TypeName.HeaderText = "名称";
            this.TypeName.Name = "TypeName";
            this.TypeName.ReadOnly = true;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1d7, 0x11e);
            base.Controls.Add(this.dataGridView1);
            base.Controls.Add(this.toolStrip1);
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "FrmList";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "机构类型列表";
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            ((ISupportInitialize) this.dataGridView1).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }
    }
}

